

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Backtest &mdash; quanttrader 0.5.0 documentation</title>
  

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />

  
  
  
  

  
  <!--[if lt IE 9]>
    <script src="_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
        <script src="_static/jquery.js"></script>
        <script src="_static/underscore.js"></script>
        <script src="_static/doctools.js"></script>
        <script src="_static/language_data.js"></script>
    
    <script type="text/javascript" src="_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Live Trading" href="livetrading.html" />
    <link rel="prev" title="Installation" href="installation.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="index.html" class="icon icon-home" alt="Documentation Home"> quanttrader
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Backtest</a></li>
<li class="toctree-l1"><a class="reference internal" href="livetrading.html">Live Trading</a></li>
</ul>
<p class="caption"><span class="caption-text">Codes</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="brokerage.html">Brokerage</a></li>
<li class="toctree-l1"><a class="reference internal" href="data.html">Data</a></li>
<li class="toctree-l1"><a class="reference internal" href="event.html">Event</a></li>
<li class="toctree-l1"><a class="reference internal" href="gui.html">GUI</a></li>
<li class="toctree-l1"><a class="reference internal" href="order.html">Order</a></li>
<li class="toctree-l1"><a class="reference internal" href="performance.html">Performance</a></li>
<li class="toctree-l1"><a class="reference internal" href="position.html">Position</a></li>
<li class="toctree-l1"><a class="reference internal" href="risk.html">Risk</a></li>
<li class="toctree-l1"><a class="reference internal" href="strategy.html">Strategy</a></li>
<li class="toctree-l1"><a class="reference internal" href="tradingengine.html">Trading Engine</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">quanttrader</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html" class="icon icon-home"></a> &raquo;</li>
        
      <li>Backtest</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/backtest.md.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="backtest">
<h1>Backtest<a class="headerlink" href="#backtest" title="Permalink to this headline">¶</a></h1>
<p><a class="reference external" href="https://letianzj.github.io/quanttrading-backtest.html">This document</a> explains quanttrader backtest framework and code structure.</p>
<p><a class="reference external" href="https://github.com/letianzj/QuantResearch/tree/master/backtest">This repository</a> contains examples of some classical strategies and their Sharpe ratios, as well as grid-search based parameter optimization. The backtest is designed to be working together with the <a class="reference external" href="https://github.com/quantopian/pyfolio">pyfolio</a> library.</p>
<p>One distinctive design in backtest is that it fills market order right away instead of filling against tomorrow’s open price. After all, in the daily bar setting, it is better to send out order at 15:59:59 than waiting overnight for next day’ open. If you disagree, simply save the market order similar to limit or stop order in the BacktestBrokerage class and then fill it on next tick.</p>
<p>Currently backtest accepts three data feeds.</p>
<ul class="simple">
<li><p>Daily bar or intraday bar from Yahoo Finance. See <a class="reference external" href="https://medium.com/&#64;letian.zj/free-historical-market-data-download-in-python-74e8edd462cf?source=friends_link&amp;sk=5af814910524a593353ed3146290d50e">here</a> for how to download.</p></li>
<li><p>Historical intraday bar from Interactive Brokers. Use <a class="reference external" href="https://github.com/letianzj/quanttrader/blob/master/examples/download_historical_data_from_ib.py">this script</a> to download.</p></li>
<li><p>Live tick recorded from live trading session. <a class="reference external" href="https://t.co/rXdW8EIbWw?amp=1">This video</a> demonstrates how to do it in live session.</p></li>
</ul>
<p>It is possible to load your own data source by following the above examples.</p>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="livetrading.html" class="btn btn-neutral float-right" title="Live Trading" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="installation.html" class="btn btn-neutral float-left" title="Installation" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        
        &copy; Copyright 2020, Letian Wang

    </p>
  </div>
    
    
    
    Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>